using UnityEngine;
using System.Collections;

[System.Serializable]
public class PickupPuzzle1CodeNoteOnTrigger : MonoBehaviour {
	
	public AudioSource audioSource;
	public Texture icon;
	
	public AudioClip playOnTrigger;
	public bool onTrigger = false;
	
	private bool triggered = false;
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnTriggerEnter(Collider other) {
		if (other.tag == "Player" && !triggered && onTrigger) {
			triggered = true;
			PickupNote();
		}
	}
	
	void  OnMouseUpAsButton() { 
		PickupNote();
	}
	
	void PickupNote() {		
		audioSource.PlayOneShot(playOnTrigger);
		
		Puzzle1CodeNote newNote = new Puzzle1CodeNote();
		
		newNote.icon = icon;
		newNote.audio = audio.clip;
		newNote.audioSource = audioSource;
		Game.inventory.items[newNote.index] = newNote;
		
		Object.Destroy(gameObject);
	}
}
